/**
 * @file       EventQueue_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 20, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "EventQueue.h"
#include "gtest/gtest.h"
#include "errorcode.h"
#include "typedefine.h"
#include "KeyboardEvent.h"
#include "IEvent.h"
namespace NS_LCD_AFW
{
class CEventQueue_test : public::testing::Test
{
public:
	virtual void SetUp()
	{
	}
	virtual void TearDown()
	{
	}
};
TEST_F(CEventQueue_test,test_defualtConstruction)
{
}
TEST_F(CEventQueue_test,test_addEvent)
{
	CEventQueue queue;
	EXPECT_EQ(ERR_NULL_POINTER,queue.addEvent(NULL));

	IEvent *pEvent = new CKeyboardEvent();
	EXPECT_EQ(ERR_SUCCESS,queue.addEvent(pEvent));

	IEvent *pTheSameEvent = NULL;
	EXPECT_TRUE(queue.peekEvent(pTheSameEvent));

	EXPECT_EQ(pEvent,pTheSameEvent);
	OBJ_DESTORY(pEvent);
	pTheSameEvent = NULL;
}
TEST_F(CEventQueue_test,test_peekEvent)
{
	CEventQueue queue;
	IEvent *pTheSameEvent = NULL;
	EXPECT_FALSE(queue.peekEvent(pTheSameEvent));

	IEvent *pEvent = new CKeyboardEvent();
	EXPECT_EQ(ERR_SUCCESS, queue.addEvent(pEvent));

	EXPECT_TRUE(queue.peekEvent(pTheSameEvent));
	EXPECT_EQ(pEvent, pTheSameEvent);

	EXPECT_TRUE(queue.peekEvent(pTheSameEvent));
	EXPECT_EQ(pEvent, pTheSameEvent);

	OBJ_DESTORY(pEvent);
	pTheSameEvent = NULL;
}
TEST_F(CEventQueue_test,test_getEvent)
{
	CEventQueue queue;
	IEvent *pTheSameEvent = NULL;
	EXPECT_FALSE(queue.getEvent(pTheSameEvent));

	IEvent *pEvent = new CKeyboardEvent();
	EXPECT_EQ(ERR_SUCCESS, queue.addEvent(pEvent));

	EXPECT_TRUE(queue.getEvent(pTheSameEvent));
	EXPECT_EQ(pEvent, pTheSameEvent);

	EXPECT_FALSE(queue.getEvent(pTheSameEvent));
	EXPECT_EQ(NULL, pTheSameEvent);

	OBJ_DESTORY(pEvent);
	pTheSameEvent = NULL;
}

} /* namespace NS_LCD_AFW */
